package com.dkm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dkm.entity.UserPojo;
import com.dkm.service.MessagePojoService;
import com.dkm.service.UserPojoService;
import com.dkm.util.ResultUtil;

@RestController
@RequestMapping("/userPojo")
public class UserPojoController {

	//注入用户业务
	@Autowired
	private UserPojoService userPojoService;
	
	//注入消息业务
	@Autowired
	private MessagePojoService messagePojoService;
	
	@GetMapping
	public List<UserPojo> getAllUserPojos(String cur_user_id) {
		//获取除了当前用户的所有用户
		List<UserPojo> users=userPojoService.getUserPojosExceptCurrentUser(cur_user_id);
		
		//获取用户和当前用户的消息集合
		return userPojoService.getUserMessages(cur_user_id, users);
	}
	
	//添加消息
	@PostMapping("/addMessage")
	public ResultUtil addMessage(String sender_id,String content,String receiver_id) {
		
		return messagePojoService.addMessage(sender_id, content, receiver_id);
	}
}
